# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=godot-cpp
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=3.2
pkgrel=3
pkgdesc='C++ bindings for the Godot script API (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.godotengine.org/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-godot_headers")
makedepends=("${MINGW_PACKAGE_PREFIX}-scons")
_commit='aba8766618c6aa40c6f7b40b513e8e47cfa807f4'
source=("https://github.com/godotengine/godot-cpp/archive/${_commit}.tar.gz")
sha256sums=('aa8c3031030eb8f5fef7cb6b12d302601787624d1e69eb900a4fd19f16ab9f9e')

prepare() {
  rm -rf "${_realname}-${pkgver}"
  mv "godot-cpp-${_commit}" "${_realname}-${pkgver}"
}

build() {
  cd "${_realname}-${pkgver}"
  declare -a extra_config
  if [ "$CARCH" = "x86_64" ]; then
    extra_config+=("use_lto=yes")
    extra_config+=("bits=64")
  else
    # lto is broken on 32bit
    extra_config+=("use_lto=no")
    extra_config+=("bits=32")
  fi

  ${MINGW_PREFIX}/bin/scons ${MAKEFLAGS} \
    platform=windows \
    target=release \
    use_mingw=yes \
	headers_dir=${MINGW_PREFIX}/include/godot \
	custom_api_file=${MINGW_PREFIX}/share/godot/api.json \
    "${extra_config[@]}" \
    generate_bindings=yes
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  mkdir -p "${pkgdir}${MINGW_PREFIX}/include"
  cd include
  find . -type f -exec install -Dm644 {} "${pkgdir}${MINGW_PREFIX}/include/godot/"{} \;
  cd ..
  install -D -m644 bin/libgodot-cpp.windows.release.*.a "${pkgdir}${MINGW_PREFIX}/lib/libgodot-cpp.a"
  install -D -m644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/godot-cpp/LICENSE.md"
}
